﻿using System;

namespace OperationPlugins.Validators.DataAnnotations
{
    /// <summary>
    /// Used to resolve resources for data annotation validation operations.
    /// </summary>
    public static class DataAnnotationsValidationResourceResolver
    {
        /// <summary>
        /// Used to resolve a branch for data annotation validation operations. 
        /// </summary>
        public static event EventHandler<ResolveBranchEventArgs> ResolveBranch;

        /// <summary>
        /// Used to resolve a operation for data annotation validation operations. 
        /// </summary>
        public static event EventHandler<ResolveOperationEventArgs> ResolveOperation;

        /// <summary>
        /// Used to resolve an operation context factory for data annotation validation operations. 
        /// </summary>
        public static event EventHandler<ResolveOperationContextFactoryEventArgs> ResolveOperationContextFactory;

        /// <summary>
        /// Raises the <see cref="ResolveBranch"/> event.
        /// </summary>
        internal static void OnResolveBranch(object sender, ResolveBranchEventArgs e)
        {
            var handler = ResolveBranch;
            if (handler != null)
            {
                handler(sender, e);
            }
        }

        /// <summary>
        /// Raises the <see cref="ResolveOperation"/> event.
        /// </summary>
        internal static void OnResolveOperation(object sender, ResolveOperationEventArgs e)
        {
            var handler = ResolveOperation;
            if (handler != null)
            {
                handler(sender, e);
            }
        }

        /// <summary>
        /// Raises the <see cref="ResolveOperationContextFactory"/> event.
        /// </summary>
        internal static void OnResolveOperationContextFactory(object sender, ResolveOperationContextFactoryEventArgs e)
        {
            var handler = ResolveOperationContextFactory;
            if (handler != null)
            {
                handler(sender, e);
            }
        }
    }
}
